package com.gitee.dbswitch.admin.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.gitee.dbswitch.admin.handler.JsonListMapTypeHandler;
import com.gitee.dbswitch.admin.handler.ListPatternHandler;
import com.gitee.dbswitch.admin.handler.ListTypeHandler;
import com.gitee.dbswitch.common.entity.PatternMapper;
import com.gitee.dbswitch.common.type.CaseConvertEnum;
import com.gitee.dbswitch.common.type.ProductTableEnum;
import com.gitee.dbswitch.common.type.SyncOptionEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.type.EnumTypeHandler;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "DBSWITCH_APIASSIGNMENT_CONFIG", autoResultMap = true)
public class APIAssignmentConfigEntity {

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @TableField("api_name")
    private String apiName;

    @TableField("api_url")
    private String apiURL;

    @TableField("target_table")
    private String targetTable;

    @TableField("request_method")
    private String requestMethod;

    @TableField("request_time")
    private String requestTime;

    @TableField("assignment_id")
    private Long assignmentId;

    @TableField("target_connection_id")
    private Long targetConnectionId;

    @TableField("target_schema")
    private String targetSchema;

    @TableField(value = "table_name_case", typeHandler = EnumTypeHandler.class)
    private CaseConvertEnum tableNameCase;

    @TableField(value = "column_name_case", typeHandler = EnumTypeHandler.class)
    private CaseConvertEnum columnNameCase;

    @TableField(value = "table_name_map", typeHandler = ListPatternHandler.class)
    private List<PatternMapper> tableNameMap;

    @TableField(value = "column_name_map", typeHandler = ListPatternHandler.class)
    private List<PatternMapper> columnNameMap;

    @TableField("target_drop_table")
    private Boolean targetDropTable;

    @TableField("target_only_create")
    private Boolean targetOnlyCreate;

    @TableField("target_auto_increment")
    private Boolean targetAutoIncrement;

    @TableField(value = "target_sync_option", typeHandler = EnumTypeHandler.class)
    private SyncOptionEnum targetSyncOption;

    @TableField("before_sql_scripts")
    private String beforeSqlScripts;

    @TableField("after_sql_scripts")
    private String afterSqlScripts;

    @TableField("batch_size")
    private Integer batchSize;

    @TableField("channel_size")
    private Integer channelSize;

    @TableField("first_flag")
    private Boolean firstFlag;

    @TableField("synchronize_type")
    private String SynchronizeType;

    @TableField(value = "create_time", insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
    private Timestamp createTime;

    @TableField("api_json_root")
    private String apiJsonRoot;

    @TableField("api_json_position")
    private String apiJsonPosition;

    @TableField(value="api_params", typeHandler = JsonListMapTypeHandler.class)
    private List<Map<String,String>> apiParams;

    @TableField(value="api_headers", typeHandler = JsonListMapTypeHandler.class)
    private List<Map<String,String>> apiHeaders;

    @TableField("api_body")
    private String apiBody;

}
